<?php
/**
 * 
 * 
 * $Rev:$
 * $Author:$
 * $Date:$
 * $Id:$
 * $URL:$
 * @author: Adrian Liechti <info@jahweh.ch>
 * @copyright: 2010 Adrian Liechti, GPL3 and CC3 BY-SA
 */

defined('OUTPUT') or die();
global $pluginLoader;

session_start();
date_default_timezone_set('Europe/Zurich');
setlocale(LC_TIME, array('de_DE','de_DE@euro','de','ger'));
$now = new DateTime('now');

require_once("main/pluginLoader.class.php");
require_once("main/plugin.class.php");
require_once("main/u.class.php");
require_once('main/cfg.class.php');
require_once('log/log.php');

u::$oGroup = array('plugin', 'pluginLoader:getPluginsByCFG', 'pluginLoader:getPluginsOrder', 'pluginLoader:getPluginsOrder:list', 'pluginLoader:getRegisterByCFG', 
					'pluginLoader:loadRegister', 'pluginLoader:savePluginsToCFG', 'smarty:area', 'pluginLoader:loadConfig', 'cfg:save');
u::$oVisGr = false;
u::$oCache = true;

if (u::$oCache === false) echo '<html><head><title>AllOne Alpha (28.06.10)</title><link rel="stylesheet" href="plugins/core/test/test.css" /></head><body><pre>'."\n";


$pluginLoader	= new pluginLoader();
$log			= new log(NULL, NULL, true);

trigger_error("TEST", E_USER_WARNING);
/*try {
	throw new error();
} catch (e $e) {
	
}
throw new warning('UncatchedWarningTest');*/
trigger_error("TEST", E_USER_ERROR);

include_once($pluginLoader->dirPlugins.'/timestamp/timestamp.class.php');
$tAll = new timeStamp('all');


if (is_dir($pluginLoader->dirConfig)) {
	u::o('files', 'pluginLoader:loadConfig', 1);
	u::o('<span class="path">'.$pluginLoader->cfgPathConfig.'</span>', 'pluginLoader:loadConfig', 2);
	$pluginLoader->getConfigByCFG();
}
$tcfg =& $pluginLoader->cfg->core;
if (isset($tcfg->o) === false) {
	$co = $tcfg->addChild('o');
		$co->addAttribute('visibleGroups','0');
		$co->addAttribute('cache','1');
		$cg = $co->addChild('group');
	$tcfg->save();
}
if (isset($tcfg->freshLoad) === false) {
	$cf = $tcfg->addChild('freshLoad');
		$cf->addAttribute('active','1');
		$cf->addAttribute('saveRegister','1');
		$cf->addAttribute('savePlugins','1');
	$tcfg->save();
}


if (u::xmlTrue($tcfg->freshLoad['active'])) {
	
	$pluginLoader->loadPluginsFresh();
	$pluginLoader->loadRegister();
	$pluginLoader->registerInclude();
	
	$tSaveConfig = new timeStamp('saveConfig', false, false);
	if ($tcfg->freshLoad['saveRegister']) {
		$tSaveConfig->start('register');
		$pluginLoader->saveRegisterToCFG();
		$tSaveConfig->end();
	}
	if ($tcfg->freshLoad['savePlugins']) {
		$tSaveConfig->start('plugins');
		$pluginLoader->savePluginsToCFG();
		$tSaveConfig->end();
	}
} else {
	
	$tPL = new timeStamp('pluginLoader:loadPlugins');
	$pluginLoader->loadPlugins();
	if ($pluginLoader->getRegisterByCFG() === false) {
		$pluginLoader->loadRegister();
	}
	$pluginLoader->registerInclude();
	$tPL->end();
}


$tOutput = new timeStamp('output');
if (($outputArray = u::getOutputPath(OUTPUT)) and is_file($outputPath = $outputArray['dir'].'/'.$outputArray['path'])) {
	u::o('Output: '.OUTPUT, 'output');
	u::o('path: <span class="path">'.$outputPath.'</span>', 'output', 1);
	require_once($outputPath);
}

if (u::$oCache === false) echo '</pre></body></html>';


$pluginLoader->destruct();
?>